package com.sh.controller;

import com.sh.service.RegisterService;
import com.sh.service.impl.UploadImgService;
import com.sh.util.UploadImg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sh.dto.ResultDto;
import sh.entity.Parent;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("register")
@Api(tags = "注册接口")
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @Resource
    private UploadImgService uploadImgService;

    /**
     * 发送验证短信
     * @param parent
     * @return
     */
    @PostMapping("send/message")
    @ApiOperation(value = "发送短信方法")
    public ResultDto sendMessage(@RequestBody Parent parent){
        return registerService.sendMessage(parent);
    }

    @PostMapping("/upload")
    @ApiOperation(value = "上传头像方法")
    @ApiImplicitParams({
            // @ApiImplicitParam(paramType = "query",name = "tagIds",value = "商品标签的id数组",required = true),
            //@ApiImplicitParam(paramType = "query",name = "goodsFormats",value = "商品标签的id",required = true),
            //@ApiImplicitParam(paramType = "query",name = "goodsTypeId",value = "商品类型的id",required = true),
            @ApiImplicitParam(paramType = "form", name = "file", value = "文件对象", required = false, dataType = "__file"),
            //@ApiImplicitParam(paramType = "form", name = "files", value = "文件数组", allowMultiple = false, dataType = "__file")
    })
    public ResultDto uploadImg(@RequestParam(value = "file",required = true) MultipartFile file) throws IOException {
        return uploadImgService.upload(file);
    }

    /**
     * 注册
     * @param parent
     * @return
     */
    @PostMapping("/regist")
    @ApiOperation(value = "注册方法")
    public ResultDto regist(@RequestBody Parent parent){
        return registerService.regist(parent);
    }
}
